package org.sgx.gwteditors.client.impl1.basetypes;

import java.util.Date;

import org.sgx.gwteditors.client.impl1.edbean.EditableBean;
import org.vectomatic.file.File;

import com.google.gwt.core.client.JsDate;
import com.google.gwt.core.shared.GWT;

/**
 * represents an HTML 5 File object (possible dropped from desktop)
 * 
 * @author sg
 * 
 */
public abstract class HTML5File implements EditableBean {
	String name, mimeType, content;
	Integer size;
	Date modifiedDate; 

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMimeType() {
		return mimeType;
	}

	public void setMimeType(String mimeType) {
		this.mimeType = mimeType;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public static HTML5File from(File f) {
		HTML5File file = GWT.create(HTML5File.class);
		file.setName(f.getName());
		file.setMimeType(f.getType());
		file.setSize((int) f.getSize());
		file.setModifiedDate(new Date((long) f.getLastModifiedDate().getTime())); 
		return file;
	}

	@Override
	public String toString() {
		return getName()+
				" - size: "+getSize()+
			" - content: "+(getContent()==null ? "null":getContent().length())+
			" - modified: "+getModifiedDate(); 
	}

}
